'''
Created on Oct 11, 2012

@author: peng
'''


def _get_error_title(error):
    title = 'unknown error'
    if error:
        stack_track = error.split('StackTrace')
        if len(stack_track) > 1:
            title = stack_track[1].split('<br>')
            if len(title) > 1:
                return title[1][:200]
    return title



if __name__ == '__main__':
    error = '!!!<br><br>#Device info<br>#Mon Oct 08 20:00:19 PDT 2012<br>User=unknown<br>Brand=metropcs_us<br>TotalMem=150MB<br>Local=en_US<br>Model=HTC-PG762<br>AvailableMem=16.80MB<br>Product=htc_marvelc<br>Device=marvelc<br>Host=ABM009<br>Type=user<br>Display=GRJ22<br>PhoneModel=HTC-PG762<br>VersionName=8.8.0<br>Tags=release-keys<br>Time=20 Mar 2012 09\\:19\\:06 GMT<br>Threshold=24MB<br>PackageName=mobi.mgeek.TunnyBrowser<br>FingerPrint=metropcs_us/htc_marvelc/marvelc\\:2.3.4/GRJ22/347228.2\\:user/release-keys<br>AndroidVersion=2.3.4<br>VersionCode=168<br>CustomData=<br>Board=marvelc<br>Id=GRJ22<br>SDKVersion=10<br>AvailMem=118MB<br><br>StackTrace<br>android.database.sqlite.SQLiteDiskIOException: disk I/O error: UPDATE cache SET weight=lastaccesstime WHERE expires<=1349751619623 AND expires!=0<br> at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)<br> at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1870)<br> at android.webkit.WebViewDatabase.trimCache(WebViewDatabase.java:1121)<br> at android.webkit.CacheManager.trimCacheIfNeeded(CacheManager.java:569)<br> at android.webkit.WebViewWorker.handleMessage(WebViewWorker.java:193)<br> at android.os.Handler.dispatchMessage(Handler.java:99)<br> at android.os.Looper.loop(Looper.java:150)<br> at android.os.HandlerThread.run(HandlerThread.java:60)<br><br>'
    title = _get_error_title(error)
    print title
